//
//  JSRCloudModel.m
//  NiubilityProject
//
//  Created by Apple on 2017/12/5.
//  Copyright © 2017年 Apple. All rights reserved.
//

#import "JSRCloudModel.h"

@implementation JSRCloudModel

+(void)updaeOrSave:(RCUserInfo *)userInfo{
    JSRCloudModel *m = [JSRCloudModel findFirstWithFormat:[NSString stringWithFormat:@"WHERE userId = '%@'",userInfo.userId]];
    if (m) {
        m.userId = userInfo.userId;
        m.name   = userInfo.name;
        m.portraitUri = userInfo.portraitUri;
        [m update];
    }else{
        m = [[JSRCloudModel alloc] init];
        m.userId = userInfo.userId;
        m.name   = userInfo.name;
        m.portraitUri = userInfo.portraitUri;
        [m save];
    }
}

+(RCUserInfo *)getUserInfo:(NSString *)userId{
    JSRCloudModel *m = [JSRCloudModel findFirstWithFormat:[NSString stringWithFormat:@"WHERE userId = '%@'",userId]];
    RCUserInfo *info = [[RCUserInfo alloc] init];
    info.userId = userId;
    info.name   = JSLocalizedString(@"Anonymity");
    info.portraitUri = @"https://www.xerkv.com/Public/Home/img/head.png";
    if (m) {
        info.userId = userId;
        info.name   = m.name;
        info.portraitUri = m.portraitUri;
    }
    return info;
}
@end
